package test3_13.Calculator;

import java.util.Arrays;

public class Test1_calculator {
    /*
    int plus(int a,int b);
    int minus(int a,int b);
    int multiply(int a,int b);
    int divide(int a,int b);
    int square(int a); //平方
    int power(int a,int index); //幂
    int isPrime(int a); //是否是素数
    void sort(int[] array); //排序
     */
    public int plus(int a, int b) {
        int plus = a + b;
        System.out.println("a，b两数之和为：" + plus);
        return plus;
    }

    public int minus(int a, int b) {
        int minus = a - b;
        System.out.println("a，b两数之差为：" + minus);
        return minus;
    }

    public int multiply(int a, int b) {
        int multiply = a * b;
        System.out.println("a,b两数之积为：" + multiply);
        return multiply;
    }

    public int divide(int a, int b) {
        int divide = a / b;
        System.out.println("a，b两数之商为：" + divide);
        return divide;
    }

    public int  square(int a) {
        int square = a*a;
        System.out.println("a，b两数之商为：" + square);
        return square;
    }

    public int power(int a, int index) {
        int power = a;
        for (int i = 1; i < index; i++) {
            power = power*a;
        }
        System.out.println("a的幂为：" + power);
        return power;
    }

    public boolean isPrime(int a) {
        boolean flag = true;
        for (int i = 2; i < a/2; i++) {
            if(a % i == 0){
                flag = false;
                break;
            }
        }
        if(flag = true){
            System.out.println("是素数");
        }else {
            System.out.println("不是素数");
        }
        return flag;
    }

    public void sort(int[] array) {
        int tmp = 0;
        for (int i = 0; i < array.length; i++) {
            for (int j = i; j < array.length; j++) {
                if(array[i]>array[j]){
                    tmp = array[i];
                    array[i] = array[j];
                    array[j] = tmp;
                }
            }
        }
        System.out.println(Arrays.toString(array));
    }
}
